home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Utilities / MView / gxu / d3darcball.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-30  |  2.1 KB  |  79 lines

  1. #pragma once
  2.  
  3. #ifndef D3DARCBALL_H_
  4. #define D3DARCBALL_H_
  5.  
  6. /*//////////////////////////////////////////////////////////////////////////////
  7. //
  8. // File: d3darcball.h
  9. //
  10. // Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  11. //
  12. // Description:
  13. //    This include file contains a simple version of Shoemake's arcball code 
  14. // from GGems IV.
  15. //
  16. //
  17. //////////////////////////////////////////////////////////////////////////////*/
  18.  
  19.  
  20. class GXArcBall { // doesn't maintain previous matrix, just current...
  21. public:
  22.     GXArcBall();
  23.  
  24.     GXArcBall(const int& x, const int& y);
  25.     GXArcBall(D3DXVECTOR3 ¢er);
  26.  
  27.     void Reset(); // qDown_ become identity...
  28.  
  29.     void SetWindow(int w, int h, float r=0.9); // ball info - sets center!
  30.  
  31.     void BeginDrag(const int& x, const int& y); // start dragging
  32.     void EndDrag();   // button up - qDown_ is now qNow_
  33.  
  34.     void Mouse(const int& x, const int& y); // right from windows...
  35.  
  36.  
  37.     void GetMat(D3DXMATRIX *mat); // gets current rotation matrix...
  38.  
  39.  
  40.     void Update();
  41.  
  42. protected:
  43.  
  44.     // this function turns a screen point into a normalized
  45.     // point on the sphere...
  46.  
  47.     D3DXVECTOR3 ScreenToVector(const int& x, const int& y);
  48.  
  49.  
  50.     D3DXVECTOR3 m_vCenter; // center of arcball - on screen
  51.     
  52.     D3DXVECTOR3 m_vDown; // button down quaternion
  53.     D3DXVECTOR3 m_vCur;  // current quaternion
  54.  
  55.     D3DXQUATERNION m_qDown; // quaternion before button down
  56.     D3DXQUATERNION m_qNow;  // composite quaternion for current drag
  57.  
  58.     int m_iWidth, m_iHeight; // window dimensions
  59.     float m_fRadius;       // ball radius - in screen space
  60.  
  61.     bool m_bDrag;          // true if during drag
  62.  
  63. };
  64.  
  65. // add some helper functions - probably should be in quaternion
  66. // class or something...
  67.  
  68. // takes two points on unit sphere an angle THETA apart, returns
  69. // quaternion that represents a rotation around cross product by
  70. // 2 * theta
  71.  
  72. D3DXQUATERNION QuatFromBallPoints(const D3DXVECTOR3 &vFrom, const D3DXVECTOR3 &vTo);
  73.  
  74. // takes a quaternion and returns 2 points on unit sphere that represent quat
  75.  
  76. //void QuatToBallPoints(const GXQuaternion &quat, GXVector3 &vFrom, GXVector3 &vTo);
  77.  
  78. #endif
  79.